# -*- coding: utf-8 -*-

# DayRaport implementation generated from reading ui file 'raportDay.ui'
#
# Created: Thu May 31 20:48:40 2012
#      by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from pl.edu.budgetanalizer.GUI.raportsManagment import CategoryWidget, \
    WeryfWidget
from pl.edu.budgetanalizer.model.Category import Category
import pyodbc

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s
    

class Ui_WeryfRaport(QtGui.QWidget):
    '''
    zawiera slownik {'kategoria': podsuma}
    '''
    listOfProducers = {}  
    listOfWeryf = {}
    
    
    def getAllCategories(self):
        '''
        pobiera wszystkie kategorie i ich podsumy, wsadza do slownika
        '''
        self.listOfProducers.clear()
        conn = pyodbc.connect(self.databaseDir)
        cur = conn.cursor()
        cur.execute("select * from Categories")

        rows = cur.fetchall()
        for row in rows:
            category = Category(row.name)
            start = str(self.startdatafield.date())
            start = start[start.find("(")+1:start.find(")")]
            start = start.replace(", ", "-")
            stop = str(self.enddatafield.date())
            stop = stop[stop.find("(")+1:stop.find(")")]
            stop = stop.replace(", ", "-")
            cur.execute("select dbo.getAmountForCategoryForData(?, ? ,?)",category.name, start , stop )
            row = cur.fetchone()
            amount = row[0]
            if amount:
                self.listOfProducers[category] = amount
            else:
                self.listOfProducers[category] = .0
                
            cur.execute("select dbo.getAmountWeryf(?, ? ,?)",category.name, start , stop )
            row = cur.fetchone()
            amount = row[0]
            if amount:
                self.listOfWeryf[category] = amount
            else:
                self.listOfWeryf[category] = .0
    
        conn.close()
    
    def addCategory(self,category):
        
            categoryButton = QtGui.QPushButton(self.horizontalLayoutWidget_2)
            categoryButton.setMinimumSize(QtCore.QSize(0, 30))
            categoryButton.setObjectName(_fromUtf8("categoryButton"))
            categoryButton.connect(categoryButton, QtCore.SIGNAL("clicked()"),self.openCategoryWidget)
            self.categoryVerticalLayout.addWidget(categoryButton)
            
            priceHorizontalLayout = QtGui.QHBoxLayout()
            priceHorizontalLayout.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
            priceHorizontalLayout.setContentsMargins(-1, -1, 10, -1)
            priceHorizontalLayout.setObjectName(_fromUtf8("priceHorizontalLayout"))
            priceLabel = QtGui.QLabel(self.horizontalLayoutWidget_2)
            priceLabel.setMaximumSize(QtCore.QSize(16777215, 20))
            priceLabel.setObjectName(_fromUtf8("priceLabel"))
            priceHorizontalLayout.addWidget(priceLabel)
            measureLabel = QtGui.QLabel(self.horizontalLayoutWidget_2)
            measureLabel.setMaximumSize(QtCore.QSize(16777215, 20))
            measureLabel.setObjectName(_fromUtf8("measureLabel"))
            priceHorizontalLayout.addWidget(measureLabel)
            self.realtVerticalLayout.addLayout(priceHorizontalLayout)
            
            priceHorizontalLayout2 = QtGui.QHBoxLayout()
            priceHorizontalLayout2.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
            priceHorizontalLayout2.setContentsMargins(-1, -1, 10, -1)
            priceHorizontalLayout2.setObjectName(_fromUtf8("priceHorizontalLayout2"))
            priceLabel2 = QtGui.QLabel(self.horizontalLayoutWidget_2)
            priceLabel2.setMaximumSize(QtCore.QSize(16777215, 20))
            priceLabel2.setObjectName(_fromUtf8("priceLabel2"))
            priceHorizontalLayout2.addWidget(priceLabel2)
            measureLabel2 = QtGui.QLabel(self.horizontalLayoutWidget_2)
            measureLabel2.setMaximumSize(QtCore.QSize(16777215, 20))
            measureLabel2.setObjectName(_fromUtf8("measureLabel2"))
            priceHorizontalLayout2.addWidget(measureLabel2)
            self.amountVerticalLayout.addLayout(priceHorizontalLayout2)
            
            categoryButton.setText(QtGui.QApplication.translate("DayRaport", category.name, None, QtGui.QApplication.UnicodeUTF8))
            priceLabel.setText(QtGui.QApplication.translate("DayRaport", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">"+QtCore.QString().setNum(self.listOfProducers[category])+ "</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            measureLabel.setText(QtGui.QApplication.translate("DayRaport", "zl", None, QtGui.QApplication.UnicodeUTF8))
            priceLabel2.setText(QtGui.QApplication.translate("DayRaport", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
    "<p align=\"right\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">"+QtCore.QString().setNum(self.listOfWeryf[category])+ "</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
            measureLabel2.setText(QtGui.QApplication.translate("DayRaport", "zl", None, QtGui.QApplication.UnicodeUTF8))
            
        
    def openCategoryWidget(self):
        self.category = Category(str(self.sender().text()))
        self.categoryWidget = WeryfWidget.Ui_MainWindow()
        self.categoryWidget.setupUi(self.categoryWidget,self.category,self.databaseDir,self.startdatafield,self.enddatafield)
        self.categoryWidget.setGeometry(QtCore.QRect(0, 0, 400, 120))
        self.categoryWidget.setAutoFillBackground(True)
        self.categoryWidget.setGeometry(QtCore.QRect(360,180,420,400))
        self.categoryWidget.show()
        
    def genRaport(self):
        self.getAllCategories()
        for category in self.listOfProducers:
            self.addCategory(category)
        
        
    def setupUi(self, DayRaport, date, databaseDir):
        '''
        wygenerowanie przez gui
        '''
        
        self.databaseDir = databaseDir
        self.date = date;
        DayRaport.resize(431, 491)
        self.horizontalLayoutWidget = QtGui.QWidget(DayRaport)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 401, 41))
        self.horizontalLayoutWidget.setObjectName(_fromUtf8("horizontalLayoutWidget"))
        
        #raport label
        self.raportHorizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
        self.raportHorizontalLayout.setMargin(0)
        self.raportHorizontalLayout.setObjectName(_fromUtf8("raportHorizontalLayout"))
        self.raportLabel = QtGui.QLabel(self.horizontalLayoutWidget)
        self.raportLabel.setObjectName(_fromUtf8("raportLabel"))
        self.raportHorizontalLayout.addWidget(self.raportLabel)
        self.dataLabel = QtGui.QLabel(self.horizontalLayoutWidget)
        self.dataLabel.setObjectName(_fromUtf8("dataLabel"))
        self.raportHorizontalLayout.addWidget(self.dataLabel)
        
        #data
        self.startdatafield = QtGui.QDateEdit(DayRaport)
        self.startdatafield.setGeometry(QtCore.QRect(10, 60, 150, 20))
        self.startdatafield.setMinimumDate(QtCore.QDate.currentDate().addDays(-1000))
        self.startdatafield.setMaximumDate(QtCore.QDate.currentDate().addDays(1000))
        self.startdatafield.setDate(QtCore.QDate.currentDate())
        self.startdatafield.show()
       
        self.enddatafield = QtGui.QDateEdit(DayRaport)
        self.enddatafield.setGeometry(QtCore.QRect(201, 60, 150, 20))
        self.enddatafield.setMinimumDate(QtCore.QDate.currentDate().addDays(-1000))
        self.enddatafield.setMaximumDate(QtCore.QDate.currentDate().addDays(1000))
        self.enddatafield.setDate(QtCore.QDate.currentDate())
        self.enddatafield.show()
        
        self.genButton = QtGui.QPushButton(DayRaport)
        self.genButton.setMinimumSize(QtCore.QSize(10, 20))
        self.genButton.setMaximumSize(QtCore.QSize(50, 80))
        self.genButton.setGeometry(390, 60, 50, 23)
        self.genButton.setObjectName(_fromUtf8("genButton"))
        self.genButton.connect(self.genButton, QtCore.SIGNAL("clicked()"),self.genRaport)
        self.genButton.setText("Generuj")

        
        
        #wykres
        self.chartWidget = QtGui.QWidget(DayRaport)
        self.chartWidget.setGeometry(QtCore.QRect(20, 290, 381, 171))
        self.chartWidget.setObjectName(_fromUtf8("chartWidget"))

        #polaczenie
        self.horizontalLayoutWidget_2 = QtGui.QWidget(DayRaport)
        self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(19, 99, 381, 182))
        self.horizontalLayoutWidget_2.setObjectName(_fromUtf8("horizontalLayoutWidget_2"))
        self.togetherHorizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget_2)
        self.togetherHorizontalLayout.setMargin(0)
        self.togetherHorizontalLayout.setObjectName(_fromUtf8("togetherHorizontalLayout"))

        
        #kategorie
        self.categoryVerticalLayout = QtGui.QVBoxLayout()
        self.categoryVerticalLayout.setObjectName(_fromUtf8("categoryVerticalLayout"))
        self.noneLabel = QtGui.QLabel(self.horizontalLayoutWidget_2)
        self.noneLabel.setMinimumSize(QtCore.QSize(0, 30))
        self.noneLabel.setMaximumSize(QtCore.QSize(100, 30))
        self.noneLabel.setObjectName(_fromUtf8("noneLabel"))
        self.categoryVerticalLayout.addWidget(self.noneLabel)
        
        self.realtVerticalLayout = QtGui.QVBoxLayout()
        self.realtVerticalLayout.setObjectName(_fromUtf8("realtVerticalLayout"))
        self.realLabel = QtGui.QLabel(self.horizontalLayoutWidget_2)
        self.realLabel.setMaximumSize(QtCore.QSize(16777215, 20))
        self.realLabel.setObjectName(_fromUtf8("amountLabel"))
        self.realtVerticalLayout.addWidget(self.realLabel)
        
        self.amountVerticalLayout = QtGui.QVBoxLayout()
        self.amountVerticalLayout.setObjectName(_fromUtf8("amountVerticalLayout"))
        self.amountLabel = QtGui.QLabel(self.horizontalLayoutWidget_2)
        self.amountLabel.setMaximumSize(QtCore.QSize(16777215, 20))
        self.amountLabel.setObjectName(_fromUtf8("amountLabel"))
        self.amountVerticalLayout.addWidget(self.amountLabel)
        

        self.togetherHorizontalLayout.addLayout(self.categoryVerticalLayout)
        self.togetherHorizontalLayout.addLayout(self.realtVerticalLayout)
        self.togetherHorizontalLayout.addLayout(self.amountVerticalLayout)

        self.retranslateUi(DayRaport)
        QtCore.QMetaObject.connectSlotsByName(DayRaport)

    def retranslateUi(self, DayRaport):
        DayRaport.setWindowTitle(QtGui.QApplication.translate("DayRaport", "DayRaport", None, QtGui.QApplication.UnicodeUTF8))
        self.amountLabel.setText(QtGui.QApplication.translate("DayRaport", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt;\">Podsuma</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.realLabel.setText(QtGui.QApplication.translate("DayRaport", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt;\">Podsuma</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.noneLabel.setText(QtGui.QApplication.translate("DayRaport", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:11pt;\"> </span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.raportLabel.setText(QtGui.QApplication.translate("DayRaport", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:6.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt;\">Raport weryfikacyjny:</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))